package com.sxj.corejava.code07_面向对象.bms;

/**
 * @author 石小俊
 * @date 2025年07月22日 13:44
 */
public class LoanCreditAccount extends CreditAccount implements Loanable {
    private double loanAmount;

    public double getLoanAmount() {
        return loanAmount;
    }

    public void setLoanAmount(double loanAmount) {
        this.loanAmount = loanAmount;
    }

    @Override
    public void providerLoan(double money) {
        // 贷款金额增加
        loanAmount += money;
        // 贷款的金额会存储到账户余额
        setBalance(getBalance() + money);
    }

    @Override
    public boolean payLoan(double money) {
        // 由于此处属于贷款的信用账户
        // 因此,还贷时要求考虑当前账户余额与信用额度
        if (getBalance() + getLimit() >= money) {
            setBalance(getBalance() - money);
            loanAmount -= money;
            return true;
        }
        return false;
    }

    @Override
    public double queryLoan() {
        return loanAmount;
    }
}
